﻿using FluentMigrator.Builders.Create.Table;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Akso.Migrations
{
    internal static class MigrationExtensions
    {
        public static ICreateTableColumnOptionOrWithColumnSyntax WithIdColumnInt64(this ICreateTableWithColumnSyntax tableWithColumnSyntax)
        {
            return tableWithColumnSyntax
                .WithColumn("Id")
                .AsInt64()
                .NotNullable()
                .PrimaryKey()
                .Identity();
        }

        public static ICreateTableColumnOptionOrWithColumnSyntax WithIdColumnGuid(this ICreateTableWithColumnSyntax tableWithColumnSyntax)
        {
            return tableWithColumnSyntax
                .WithColumn("Id")
                .AsGuid()
                .NotNullable()
                .PrimaryKey();
        }

        public static ICreateTableColumnOptionOrWithColumnSyntax WithCreateColumns(this ICreateTableWithColumnSyntax tableWithColumnSyntax)
        {
            return tableWithColumnSyntax
                .WithColumn("CreationTime").AsDateTime().NotNullable().WithDefault(FluentMigrator.SystemMethods.CurrentDateTime)
                .WithColumn("CreatorUserId").AsInt64().Nullable();
        }

        public static ICreateTableColumnOptionOrWithColumnSyntax WithModifyColumns(this ICreateTableWithColumnSyntax tableWithColumnSyntax)
        {
            return tableWithColumnSyntax
                .WithColumn("LastModificationTime").AsDateTime().Nullable()
                .WithColumn("LastModifierUserId").AsInt64().Nullable();
        }

        public static ICreateTableColumnOptionOrWithColumnSyntax WithCreateAndModifyColumns(this ICreateTableWithColumnSyntax tableWithColumnSyntax)
        {
            return tableWithColumnSyntax
                .WithColumn("CreationTime").AsDateTime().NotNullable().WithDefault(FluentMigrator.SystemMethods.CurrentDateTime)
                .WithColumn("CreatorUserId").AsInt64().Nullable()
                .WithColumn("LastModificationTime").AsDateTime().Nullable()
                .WithColumn("LastModifierUserId").AsInt64().Nullable();
        }

        public static ICreateTableColumnOptionOrWithColumnSyntax WithDeleteColumns(this ICreateTableWithColumnSyntax tableWithColumnSyntax)
        {
            return tableWithColumnSyntax
                .WithColumn("DeletionTime").AsDateTime().Nullable()
                .WithColumn("DeleterUserId").AsInt64().Nullable()
                .WithColumn("IsDeleted").AsBoolean().Nullable().WithDefaultValue(false);
        }

        public static ICreateTableColumnOptionOrWithColumnSyntax WithCreateAndDeleteColumns(this ICreateTableWithColumnSyntax tableWithColumnSyntax)
        {
            return tableWithColumnSyntax
                .WithColumn("CreationTime").AsDateTime().NotNullable().WithDefault(FluentMigrator.SystemMethods.CurrentDateTime)
                .WithColumn("CreatorUserId").AsInt64().Nullable()
                .WithColumn("DeletionTime").AsDateTime().Nullable()
                .WithColumn("DeleterUserId").AsInt64().Nullable()
                .WithColumn("IsDeleted").AsBoolean().Nullable().WithDefaultValue(false);
        }

        public static ICreateTableColumnOptionOrWithColumnSyntax WithAuditColumns(this ICreateTableWithColumnSyntax tableWithColumnSyntax)
        {
            return tableWithColumnSyntax
                .WithColumn("CreationTime").AsDateTime().NotNullable().WithDefault(FluentMigrator.SystemMethods.CurrentDateTime)
                .WithColumn("CreatorUserId").AsInt64().Nullable()
                .WithColumn("LastModificationTime").AsDateTime().Nullable()
                .WithColumn("LastModifierUserId").AsInt64().Nullable()
                .WithColumn("DeletionTime").AsDateTime().Nullable()
                .WithColumn("DeleterUserId").AsInt64().Nullable()
                .WithColumn("IsDeleted").AsBoolean().Nullable().WithDefaultValue(false);
        }

        public static ICreateTableColumnOptionOrWithColumnSyntax WithActiveColumn(this ICreateTableWithColumnSyntax tableWithColumnSyntax)
        {
            return tableWithColumnSyntax
                .WithColumn("IsActive").AsBoolean().Nullable().WithDefaultValue(true);
        }
        
        public static ICreateTableColumnOptionOrWithColumnSyntax AsMaxString(this ICreateTableColumnAsTypeSyntax createTableColumnAsTypeSyntax)
        {
            return createTableColumnAsTypeSyntax.AsString(int.MaxValue);
        }

        public static ICreateTableColumnOptionOrWithColumnSyntax AsMaxBinary(this ICreateTableColumnAsTypeSyntax createTableColumnAsTypeSyntax)
        {
            return createTableColumnAsTypeSyntax.AsCustom("LONGBLOB");
        }

    }
}
